package com.xinzhidi.web.netty.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.netty.entity.dto.AgreementHouseholdValveAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHouseholdValveListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHouseholdValveUpdDto;
import com.xinzhidi.web.netty.entity.vo.AgreementHouseholdValveInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementHouseholdValveListVo;
import com.xinzhidi.web.netty.service.AgreementHouseholdValveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 户用阀门协议-（实时数据）Controller
 *
 * @author cx
 * @date 2023-06-13
 */
@RestController
@Api(tags = "户用阀门协议-（实时数据）")
@RequestMapping("/agreementHouseholdValve")
public class AgreementHouseholdValveController extends BaseController {
    @Autowired
    private AgreementHouseholdValveService agreementHouseholdValveService;

    @ApiOperation("查询户用阀门协议-（实时数据）列表")
    @PreAuthorize("@ss.hasPermi('agreementHouseholdValve:agreementHouseholdValve:list')")
    @PostMapping("/listAgreementHouseholdValve")
    public TableDataInfo<AgreementHouseholdValveListVo> listAgreementHouseholdValve(@Validated @RequestBody AgreementHouseholdValveListDto dto) {
        startPagePost(dto);
        return agreementHouseholdValveService.selectAgreementHouseholdValveList(dto);
    }

    @ApiOperation("导出户用阀门协议-（实时数据）列表")
    @PreAuthorize("@ss.hasPermi('agreementHouseholdValve:agreementHouseholdValve:export')")
    @Log(title = "户用阀门协议-（实时数据）", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgreementHouseholdValve")
    public void exportAgreementHouseholdValve(HttpServletResponse response, AgreementHouseholdValveListDto dto) {
        TableDataInfo<AgreementHouseholdValveListVo> list = agreementHouseholdValveService.selectAgreementHouseholdValveList(dto);
        ExcelUtil<AgreementHouseholdValveListVo> util = new ExcelUtil<AgreementHouseholdValveListVo>(AgreementHouseholdValveListVo.class);
        util.exportExcel(response, list.getRows(), "户用阀门协议-（实时数据）数据");
    }

    @ApiOperation("获取户用阀门协议-（实时数据）详细信息")
    @PreAuthorize("@ss.hasPermi('agreementHouseholdValve:agreementHouseholdValve:query')")
    @GetMapping(value = "/getAgreementHouseholdValveById")
    public R<AgreementHouseholdValveInfoVo> getAgreementHouseholdValveById(@RequestParam("id") Long id) {
        return R.ok(agreementHouseholdValveService.selectAgreementHouseholdValveById(id));
    }

    @ApiOperation("新增户用阀门协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementHouseholdValve:agreementHouseholdValve:add')")
    @Log(title = "户用阀门协议-（实时数据）", businessType = BusinessType.INSERT)
    @PostMapping("addAgreementHouseholdValve")
    public AjaxResult addAgreementHouseholdValve(@Validated @RequestBody AgreementHouseholdValveAddDto dto) {
        return toAjax(agreementHouseholdValveService.insertAgreementHouseholdValve(dto));
    }

    @ApiOperation("修改户用阀门协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementHouseholdValve:agreementHouseholdValve:edit')")
    @Log(title = "户用阀门协议-（实时数据）", businessType = BusinessType.UPDATE)
    @PostMapping("editAgreementHouseholdValve")
    public AjaxResult editAgreementHouseholdValve(@Validated @RequestBody AgreementHouseholdValveUpdDto dto) {
        return toAjax(agreementHouseholdValveService.updateAgreementHouseholdValve(dto));
    }

    @ApiOperation("删除户用阀门协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementHouseholdValve:agreementHouseholdValve:remove')")
    @Log(title = "户用阀门协议-（实时数据）", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAgreementHouseholdValve")
    public AjaxResult delAgreementHouseholdValve(@RequestParam Long[] ids) {
        return toAjax(agreementHouseholdValveService.deleteAgreementHouseholdValveByIds(ids));
    }

    @ApiOperation("户用阀门-【写阀门地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "oldAddress", value = "原地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "newAddress", value = "现地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/writeValveAddress")
    public AjaxResult writeValveAddress(Long dtuId, String oldAddress, String newAddress) {
        return toAjax(agreementHouseholdValveService.writeValveAddress(dtuId, oldAddress, newAddress));
    }

    @ApiOperation("户用阀门-【读阀门地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class)
    })
    @GetMapping("/readValveAddress")
    public AjaxResult readValveAddress(Long dtuId) {
        return toAjax(agreementHouseholdValveService.readValveAddress(dtuId));
    }

    @ApiOperation("户用阀门-【读阀门当前AD值】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/readADValue")
    public AjaxResult readADValue(Long dtuId, String address) {
        return toAjax(agreementHouseholdValveService.readADValue(dtuId, address));
    }

    @ApiOperation("户用阀门-【读 阀门信息（工作模式等）】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/readValue")
    public AjaxResult readValue(Long dtuId, String address) {
        return toAjax(agreementHouseholdValveService.readValue(dtuId, address));
    }

    @ApiOperation("户用阀门-【读传感器数据】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/readSensorValue")
    public AjaxResult readSensorValue(Long dtuId, String address) {
        return toAjax(agreementHouseholdValveService.readSensorValue(dtuId, address));
    }

    @ApiOperation("户用阀门-【写阀门校准开度AD值】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "kadh", value = "全开AD值高位", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "kadl", value = "全开AD值低位", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "gadh", value = "全关AD值高位", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "gadl", value = "全关AD值低位", dataType = "int", dataTypeClass = Integer.class),
    })
    @GetMapping("/writeCalibrate")
    public AjaxResult writeCalibrate(Long dtuId, String address , Integer kadh , Integer kadl , Integer gadh , Integer gadl) {
        return toAjax(agreementHouseholdValveService.writeCalibrate(dtuId, address , kadh , kadl , gadh , gadl));
    }

    @ApiOperation("户用阀门-【阀门工作模式】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mode", value = "模式", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/valveOperatingMode")
    public AjaxResult valveOperatingMode(Long dtuId, String address, String mode) {
        return toAjax(agreementHouseholdValveService.valveOperatingMode(dtuId, address, mode));
    }

    @ApiOperation("户用阀门-【写阀门掉电开度】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class) ,
            @ApiImplicitParam(name = "valveOpen", value = "掉电开度", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("/writeValvePowerDown")
    public AjaxResult writeValvePowerDown(Long dtuId, String address , Integer valveOpen) {
        return toAjax(agreementHouseholdValveService.writeValvePowerDown(dtuId, address , valveOpen));
    }


    @ApiOperation("户用阀门-【写 阀门时间】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class) ,
            @ApiImplicitParam(name = "yy", value = "年", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mm", value = "月", dataType = "String", dataTypeClass = String.class) ,
            @ApiImplicitParam(name = "dd", value = "日", dataType = "String", dataTypeClass = String.class) ,
            @ApiImplicitParam(name = "hh", value = "时", dataType = "String", dataTypeClass = String.class) ,
            @ApiImplicitParam(name = "mi", value = "分", dataType = "String", dataTypeClass = String.class) ,
            @ApiImplicitParam(name = "ss", value = "秒", dataType = "String", dataTypeClass = String.class) ,
    })
    @GetMapping("/writeValveTime")
    public AjaxResult writeValveTime(Long dtuId, String address , String yy , String mm , String dd , String hh , String mi , String ss) {
        return toAjax(agreementHouseholdValveService.writeValveTime(dtuId, address , yy , mm , dd , hh , mi , ss));
    }


    @ApiOperation("户用阀门-【读 阀门数据（开度，温度）】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/readValve")
    public AjaxResult readValve(Long dtuId, String address) {
        return toAjax(agreementHouseholdValveService.readValve(dtuId, address));
    }

    @ApiOperation("户用阀门-【写 阀门数据（开度）】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "valveOpen", value = "开度值（十进制）", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("/writeValveOpen")
    public AjaxResult writeValveOpen(Long dtuId, String address, Integer valveOpen) {
        return toAjax(agreementHouseholdValveService.writeValveOpen(dtuId, address, valveOpen));
    }

    @ApiOperation("户用阀门-【清零指令】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/clearInstruction")
    public AjaxResult clearInstruction(Long dtuId, String address) {
        return toAjax(agreementHouseholdValveService.clearInstruction(dtuId, address));
    }

    @ApiOperation("户用阀门-【阀门维护】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/valveMaintenance")
    public AjaxResult valveMaintenance(Long dtuId, String address) {
        return toAjax(agreementHouseholdValveService.valveMaintenance(dtuId, address));
    }

    @ApiOperation("户用阀门-【写 阀门断电开度】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "valveOpen", value = "断电开度（十进制）", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("/writeValvePowerOpen")
    public AjaxResult writeValvePowerOpen(Long dtuId, String address, Integer valveOpen) {
        return toAjax(agreementHouseholdValveService.writeValvePowerOpen(dtuId, address, valveOpen));
    }


}
